import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/loading/l_error_widget.dart';
import 'package:xvideos/tools_base/loading/loading_center_widget.dart';
import 'package:xvideos/tools_base/refresh/pull_refresh.dart';

import 'mine_withdrawal_record_logic.dart';

enum RecordType {
  recharge('充值记录'),
  withdraw('提现明细'),
  bill('金币明细'),
  income('业绩明细');

  final String title;
  const RecordType(this.title);
}

//明细综合页面
class RecordsPage extends StatefulWidget {
  final RecordType type; // 0：收益， 1： 提现
  const RecordsPage(this.type, {super.key});

  @override
  State<RecordsPage> createState() => _RecordsPageState();
}

class _RecordsPageState extends State<RecordsPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MineWithdrawalRecordLogic>(
      init: instanceController(widget.type),
      builder: (controller) {
        return Scaffold(
          appBar: AppBar(
              title: Text(
            widget.type.title,
            style: textStyle(18, Color(0xE5FFFFFF), FontWeight.w600),
          )),
          body: pullYsRefresh(
            onRefresh: (refreshController) => controller.fetchPageData(),
            onLoading: (refreshController) => controller.fetchPageData(isRefresh: false),
            onInit: (ctr) => controller.refreshController = ctr,
            child: () {
              if (controller.isLoading) return LoadingCenterWidget();
              if (controller.dataSource.isEmpty) return CErrorWidget(retryOnTap: () => controller.fetchPageData());

              return ListView.builder(
                itemCount: controller.dataSource.length,
                padding: EdgeInsets.only(top: 12, left: 16.w, right: 16.w),
                itemBuilder: (context, index) => controller.instanceChildItem(index),
              );
            }(),
          ),
        );
      },
    );
  }
}
